import vv from "./vv";
import GameData from "./GameData";

const {ccclass, property} = cc._decorator;

@ccclass
export default class RankingView extends cc.Component {

    @property(cc.Node)
    groupFriendButton: cc.Node = null;
    @property(cc.Node)
    friendButton: cc.Node = null;
    @property(cc.Node)
    gameOverButton: cc.Node = null;
    @property(cc.Sprite)
    rankingScrollView: cc.Sprite = null;//显示排行榜

    //关闭排行
    @property(cc.Node)
    return:cc.Node = null


    //背景
    @property(cc.Node)
    bg:cc.Node = null


    onEnable()
    {
        let luogang = 
            {
                "luogang":"哈哈",
                "luogang1":"哈哈",
                "luogang2":"哈哈",
                "luogang3":"哈哈",
                "luogang4":"哈哈",
                "luogang5":"哈哈"
            }
        if (window['wx']) {
            window['wx'].showShareMenu({withShareTicket: true});//设置分享按钮，方便获取群id展示群排行榜
            this.tex = new cc.Texture2D();
            window.sharedCanvas.width = 720;
            window.sharedCanvas.height = 1280;
            window['wx'].postMessage({
                messageType: 1,
                MAIN_MENU_NUM: "maxguanka"
            });
        }
    }

    start() {

      
        let luogang = 
        {
            "luogang":"哈哈",
            "luogang1":"哈哈",
            "luogang2":"哈哈",
            "luogang3":"哈哈",
            "luogang4":"哈哈",
            "luogang5":"哈哈"
        }
        vv.btnClick(this.return,()=>
        {
            if(GameData.Instance.shaichevoiceOnOrOff == true)
            {
                cc.find('Canvas/AudioManager').children[5].getComponent(cc.AudioSource).play()
            }
          
            this.node.active = false
        })


      
    }

    friendButtonFunc(event) {


        if (CC_WECHATGAME) {

            let kvdata = [{ key: "maxguanka", value: JSON.stringify(GameData.Instance.guanka)}]
            window['wx'].setUserCloudStorage({
                KVDataList: kvdata,
                success: res => {
                    console.log('存储数据成功',res)
                }, fail: res => {
                    console.log('存储数据失败',res)
                }
            })

            // 发消息给子域
            window['wx'].postMessage({
                messageType: 1,
                MAIN_MENU_NUM: "maxguanka"
            });
        } else {
            cc.log("获取好友排行榜数据。x1");
        }
    }


    // 刷新子域的纹理
    _updateSubDomainCanvas() {
            var openDataContext = wx.getOpenDataContext();
            var sharedCanvas = openDataContext.canvas;
            this.tex.initWithElement(sharedCanvas);
            this.tex.handleLoadedTexture();
            this.rankingScrollView.spriteFrame = new cc.SpriteFrame(this.tex);
    }

    update() {
        this._updateSubDomainCanvas();
    }
}
